package helpers

import (
  "crypto/md5"
  "encoding/hex"
  "path"
  "strconv"
  "time"
)

type Hash struct {
}

func NewHash() *Hash {
  return &Hash{}
}

func (that *Hash) Md5(str string) string {
  h := md5.New()
  h.Write([]byte(str))
  return hex.EncodeToString(h.Sum(nil))
}

func (that *Hash) CreateFileName(filename string) string {
  md5Str := that.Md5(strconv.FormatInt(time.Now().UnixNano(), 10) + filename)
  return md5Str[0:2] + "/" + md5Str[2:5] + "/" + md5Str[5:] + path.Ext(filename)
}
